import { objDeepCopy,getDateString } from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {
		
	},
	methods: {
		init() {
			this.getList(this);//收料 160
		},
		//获取收料列表
		getList(that, params,page) {
			params = params || {businessType: 160},
			page = page || this.Model.page;
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/supplier/whWarehouse/materialsList',
				// url:'/api/supplier/whWarehouse/materialsList',
				data: {
					condition:params,
					pageIndex:page.pageIndex,
					pageSize:page.pageSize
				}
			}).then((res) => {
				var data = res.data;
				that.Model.tableData = [];
				if (data.status == 200) {
					var result = data.result.result;
					var obj;
					var pagination = commonObject.paginationFunction(data.result);
					that.Model.paginationObject = objDeepCopy(pagination);
					if (result) {
						for (let i = 0; i < result.length; i++) {
							obj = objDeepCopy(result[i]);
							obj.showStatus = result[i].statusDict.value;
							that.Model.tableData.push(obj);
						}
					}
		
				} else {
					that.tips(that, 'warning', data.msg);
				}
		
			});
		},
		//点击收料
		toReceiptStorage(){
			this.$router.push({
				path: 'receiptStorage',
				query: {
					
				}
			});
		},
		//点击退料
		toReturn(){
			var TableSelectData = this.Model.TableSelectData;
			var arr = [];
			var notArr = [];
			if(TableSelectData.length == 0){
				this.tips(this, 'warning', '请选择需要退料的数据');
				return;
			}else{
				for (let i = 0; i < TableSelectData.length; i++) {
					if(TableSelectData[i].status == 8){
						arr.push(TableSelectData[i].barCode);
					}else{
						notArr.push(TableSelectData[i].barCode);
					}
				}
				if(notArr.length == 0){
					this.$router.push({
						path: 'ReturnOrderListNew',
						query: {
							barCodeArr:arr
						}
					});
				}else{
					this.tips(this, 'warning', '只有已收料的情况才能退料');
				}
				//
			}
			
		},
		//详情
		toDetial(row){
			this.$router.push({
				path: 'receiptListDetail',
				query: {
					barCode:row.barCode
				}
			});
		},
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			this.Model.TableSelectData = val
		},
		handleCurrentChange(val) {
			var params = this.Model.searchFromData;
			var page = this.Model.page;
			page.pageIndex = val;
			this.getList(this,params,page);
		},
		handleSizeChange(val) {
			var params = this.Model.searchFromData;
			var page = this.Model.page;
			page.pageSize = val;
			this.getList(this,params,page);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			var obj;
			obj = {
				keyWord: val.keyWord,
				status: val.status,
				businessType: 160
			}
			if(val.receiptTime){
				obj.gMaterialStartTime = getDateString(val.receiptTime[0]);
				obj.gMaterialEndTime = getDateString(val.receiptTime[1]);
			}
			if(val.issueTime){
				obj.sTimeStart = getDateString(val.issueTime[0]);
				obj.sTimeEnd = getDateString(val.issueTime[1]);
			}
			this.Model.searchFromData = objDeepCopy(obj);
		},
		toSearch(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params);
		},
		toClear(val) {
			this.Model.searchFromData = this.Model.defaultSearchFromData;
		},
		toExport(val) {
		  console.log(val);
		},
		onTabChange(val) {
			console.log(val, this.Model.activeTab)
			switch (val) {
				case 1:
					break;
				case 2:
					break;
				case 3:
					break;
			}
		},
		tips(that, type, message) {
			let duration;
			type == 'success' ? duration = 3000 : duration = 10000;
			that.$message({
				message: message,
				type: type,
				duration: duration
			});
		},
	},
	watch:{
		$route:{
		　　　handler(newValue, oldValue) {
				
		　　　},
		　　　deep: true
		},
  	
	},
	filters:{
		objFilters:function(value){
			
		}
	}
}
export default Controller;
